package com.misc.pebblewatch;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.BitmapFactory;

import com.roymam.android.notificationswidget.R;

/**
 * Created by adminsag on 10/12/14.
 */
public class NotificationGeneration {

    public static int THIS_NOTIF_ID = 1;
    public static int PENDING_REQUEST_CODE = 1;

    public void addNotification(Context ctx) {

        Intent notificationIntent = new Intent(ctx, getClass());
        PendingIntent contentIntent = PendingIntent.getActivity(ctx,
                PENDING_REQUEST_CODE, notificationIntent,
                PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationManager nm = (NotificationManager) ctx
                .getSystemService(Context.NOTIFICATION_SERVICE);

        Resources res = ctx.getResources();
        Notification.Builder builder = new Notification.Builder(ctx);

        builder.setContentIntent(contentIntent)
                .setSmallIcon(R.drawable.generic_icon)
                .setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.amazon))
                .setTicker(res.getString(R.string.test_notification_ticker))
                .setWhen(System.currentTimeMillis())
                .setAutoCancel(true)
                .setContentTitle(res.getString(R.string.test_notification_title))
                .setContentText(res.getString(R.string.test_notification_text) + " " + System.currentTimeMillis());
        Notification n = builder.build();

        nm.notify(THIS_NOTIF_ID, n);
    }

    // Remove notification
    private void removeNotification(Context ctx) {
        NotificationManager manager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);
        manager.cancel(THIS_NOTIF_ID);
    }
}
